//
//  HWBookTicketHeadView.m
//  嗨文
//
//  Created by 响当当 on 2019/2/22.
//  Copyright © 2019年 dongzheng. All rights reserved.
//

#import "HWBookTicketHeadView.h"
#import "HWReChargeViewController.h"
#import "HWBookPassTimeViewController.h"

@interface HWBookTicketHeadView()
@property (nonatomic, strong)UILabel *bookCoinLabel;//书币
@property (nonatomic, strong)UILabel *bookCouponLabel;//赠送的券
@property (nonatomic, strong)UIButton *timeButton;//有效期
@end

@implementation HWBookTicketHeadView

- (UILabel *)bookCoinLabel
{
    if (!_bookCoinLabel)
    {
        _bookCoinLabel = [HWUtilties creatLabelWithFrame:CGRectMake(33*kUIScaleBasePlus,58*kUIScaleBasePlus,0,26*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentCenter
                                                textClor:LCHexColor(0xFFFFFF)
                                                textFont:25*kUIScaleBasePlus];
    }
    return _bookCoinLabel;
}

- (UILabel *)bookCouponLabel
{
    if (!_bookCouponLabel)
    {
        _bookCouponLabel = [HWUtilties creatLabelWithFrame:CGRectMake(160*kUIScaleBasePlus,58*kUIScaleBasePlus,0,26*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentCenter
                                                textClor:LCHexColor(0xFFFFFF)
                                                textFont:25*kUIScaleBasePlus];
    }
    return _bookCouponLabel;
}

- (UIButton *)timeButton
{
    if (!_timeButton)
    {
        _timeButton = [HWUtilties creatButtonWithFrame:CGRectMake(0,67*kUIScaleBasePlus,60*kUIScaleBasePlus,19*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentCenter
                                                  text:@"有效期 >"
                                              textClor:LCHexColor(0xFFC74E)
                                             buttonBGC:LCHexColor(0x1A1A1A)
                                              textFont:10*kUIScaleBasePlus
                                                target:self
                                                method:@selector(timeClick)];
        _timeButton.layer.masksToBounds = YES;
        _timeButton.layer.cornerRadius = 3;
    }
    return _timeButton;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creatUI];
    }
    return self;
}

#pragma mark - creatUI
- (void)creatUI
{
    
    UIImageView *bgImageView= [[UIImageView alloc]initWithFrame:CGRectMake(0,0,SCREEN_WIDTH,160*kUIScaleBasePlus)];
    bgImageView.image = [UIImage imageNamed:@"ticket_bg"];
    bgImageView.userInteractionEnabled = YES;//划重点
    [self addSubview:bgImageView];
    
    UILabel *bookCoinSurplusLabel = [HWUtilties creatLabelWithFrame:CGRectMake(31*kUIScaleBasePlus,32*kUIScaleBasePlus,80*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                       textAligment:NSTextAlignmentLeft
                                                           textClor:LCHexColor(0xDBDBDB)
                                                           textFont:12*kUIScaleBasePlus];
    bookCoinSurplusLabel.text = @"书币账户余额";
    [bgImageView addSubview:bookCoinSurplusLabel];
    
    UILabel *bookTicketSurplusLabel = [HWUtilties creatLabelWithFrame:CGRectMake(160*kUIScaleBasePlus,32*kUIScaleBasePlus,80*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                                       textAligment:NSTextAlignmentLeft
                                                           textClor:LCHexColor(0xDBDBDB)
                                                           textFont:12*kUIScaleBasePlus];
    bookTicketSurplusLabel.text = @"书券账户余额";
    [bgImageView addSubview:bookTicketSurplusLabel];
    
    [bgImageView addSubview:self.bookCoinLabel];
    
    [bgImageView addSubview:self.bookCouponLabel];
    
    [bgImageView addSubview:self.timeButton];
    
    UILabel *readLabel = [HWUtilties creatLabelWithFrame:CGRectMake(32*kUIScaleBasePlus,105*kUIScaleBasePlus,120*kUIScaleBasePlus,12*kUIScaleBasePlus)
                                            textAligment:NSTextAlignmentLeft
                                                textClor:LCHexColor(0xFFC74E)
                                                textFont:12*kUIScaleBasePlus];
    readLabel.text = @"阅读时优先扣除书券";
    [bgImageView addSubview:readLabel];
    
    UIButton *rechargeButton = [HWUtilties creatButtonWithFrame:CGRectMake(16*kUIScaleBasePlus,195*kUIScaleBasePlus,343*kUIScaleBasePlus,40*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentCenter
                                              text:@"充值"
                                          textClor:LCHexColor(0xFFFFFF)
                                         buttonBGC:LCHexColor(0xF54337)
                                          textFont:16*kUIScaleBasePlus
                                            target:self
                                            method:@selector(recharge)];
    rechargeButton.layer.masksToBounds = YES;
    rechargeButton.layer.cornerRadius = 2;
    [self addSubview:rechargeButton];
    
    
    UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(16*kUIScaleBasePlus,265*kUIScaleBasePlus,359*kUIScaleBasePlus,1*kUIScaleBasePlus)];
    lineView.backgroundColor = LCHexColor(0xEBE5E1);
    [self addSubview:lineView];

}

#pragma mark - 获取数据
- (void)geyDate:(NSDictionary *)dic
{
    NSString *bookCoin = [NSString stringWithFormat:@"%@书币",dic[@"bookCoin"]];
    self.bookCoinLabel.attributedText = [bookCoin addAttriButedString:bookCoin
                                                                Color:LCHexColor(0xDBDBDB)
                                                                 Font:[UIFont systemFontOfSize:12*kUIScaleBasePlus]
                                                                 rang:NSMakeRange(bookCoin.length-2,2)];
    [self.bookCoinLabel sizeToFit];
    
    
    NSString *bookTicket = [NSString stringWithFormat:@"%@(书券)",IFNULL(dic[@"bookCoupon"],[NSString stringWithFormat:@"0"])];
    self.bookCouponLabel.attributedText = [bookTicket addAttriButedString:bookTicket
                                                                Color:LCHexColor(0xDBDBDB)
                                                                 Font:[UIFont systemFontOfSize:12*kUIScaleBasePlus]
                                                                 rang:NSMakeRange(bookTicket.length-4,4)];
    [self.bookCouponLabel sizeToFit];
    
    [self.timeButton setX:CGRectGetMaxX(self.bookCouponLabel.frame)+4*kUIScaleBasePlus];
    
}

#pragma mark - Method
//有效期
- (void)timeClick
{
    HWBookPassTimeViewController *vc = [[HWBookPassTimeViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
}

//充值
- (void)recharge
{
    HWReChargeViewController *vc = [[HWReChargeViewController alloc]init];
    vc.hidesBottomBarWhenPushed = YES;
    [[HWUtilties getCurrentVC].navigationController pushViewController:vc animated:YES];
}
@end
